home *** CD-ROM | disk | FTP | other *** search
/ The AGA Experience 3 / AGA Experience Volume 3 (1997)(NFA - SAdENESS)[!].iso / software / utilities / programmers / c_dt / dt_source / libinit.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-03  |  4.4 KB  |  150 lines

  1. /*
  2. **      $VER: LibInit.c 43.4 (3.1.97)
  3. **
  4. **      Library initializers and functions to be called by StartUp.c
  5. **
  6. **      (C) Copyright 1996-97 Andreas R. Kleinert
  7. **      All Rights Reserved.
  8. */
  9.  
  10. #define __USE_SYSBASE
  11.  
  12. #include <exec/types.h>
  13. #include <exec/memory.h>
  14. #include <exec/libraries.h>
  15. #include <exec/execbase.h>
  16. #include <exec/resident.h>
  17. #include <exec/initializers.h>
  18. #include <datatypes/pictureclass.h>
  19.  
  20. #include <proto/exec.h>
  21. #include <proto/intuition.h>
  22. #include <proto/datatypes.h>
  23.  
  24. #include <class/classbase.h>
  25. #include "libfuncs.h"
  26.  
  27.  
  28. ULONG __saveds __stdargs L_OpenLibs(void);
  29. void  __saveds __stdargs L_CloseLibs(void);
  30.  
  31. extern struct ClassBase *ClassBase;
  32.  
  33.  
  34. struct ExecBase      *SysBase        = NULL;
  35. struct DosLibrary    *DOSBase        = NULL;
  36. struct IntuitionBase *IntuitionBase  = NULL;
  37. struct GfxBase       *GfxBase        = NULL;
  38. struct Library       *UtilityBase    = NULL;
  39. struct Library       *DataTypesBase  = NULL;
  40. struct Library       *SuperClassBase = NULL;
  41. struct Library       *IFFParseBase   = NULL;
  42.  
  43.  
  44. #define VERSION  43
  45. #define REVISION 3
  46.  
  47. char __aligned ExLibName [] = "samplePNM.datatype";
  48. char __aligned ExLibID   [] = "samplePNM 43.3 (30.11.96)";
  49. char __aligned Copyright [] = "(C)opyright 1996 by Andreas R. Kleinert. All rights reserved.";
  50.  
  51. extern ULONG InitTab[];
  52.  
  53. extern APTR EndResident; /* below */
  54.  
  55. struct Resident __aligned ROMTag =
  56. {
  57.  RTC_MATCHWORD,
  58.  &ROMTag,
  59.  &EndResident,
  60.  RTF_AUTOINIT,
  61.  VERSION,
  62.  NT_LIBRARY,
  63.  0,
  64.  &ExLibName[0],
  65.  &ExLibID[0],
  66.  &InitTab[0]
  67. };
  68.  
  69. APTR EndResident;
  70.  
  71. struct MyDataInit
  72. {
  73.  UWORD ainit1; UWORD binit1; UWORD ln_type;
  74.  UBYTE ainit2; UBYTE binit2; ULONG ln_name2;
  75.  UWORD ainit3; UWORD binit3; UWORD lib_flags;
  76.  UWORD ainit4; UWORD binit4; UWORD lib_version;
  77.  UWORD ainit5; UWORD binit5; UWORD lib_revision;
  78.  UBYTE ainit6; UBYTE binit6; ULONG lib_idstring2;
  79.  ULONG end;
  80. } DataTab =
  81. {
  82.  INITBYTE(OFFSET(Node,         ln_Type),      NT_LIBRARY),
  83.  0x80, (UBYTE) OFFSET(Node,    ln_Name),      (ULONG) &ExLibName[0],
  84.  INITBYTE(OFFSET(Library,      lib_Flags),    LIBF_SUMUSED|LIBF_CHANGED),
  85.  INITWORD(OFFSET(Library,      lib_Version),  VERSION),
  86.  INITWORD(OFFSET(Library,      lib_Revision), REVISION),
  87.  0x80, (UBYTE) OFFSET(Library, lib_IdString), (ULONG) &ExLibID[0],
  88.  (ULONG) 0
  89. };
  90.  
  91.  /* Libraries not shareable between Processes or libraries messing
  92.     with RamLib (deadlock and crash) may not be opened here - open/close
  93.     these later locally and or maybe close them fromout L_CloseLibs()
  94.     when expunging !
  95.  */
  96.  
  97. ULONG __saveds __stdargs L_OpenLibs(void)
  98. {
  99.  SysBase = (*((struct ExecBase **) 4));
  100.  
  101.  DOSBase = (struct DosLibrary *) OpenLibrary("dos.library", 39);
  102.  if(!DOSBase) return(FALSE);
  103.  
  104.  IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library", 39);
  105.  if(!IntuitionBase) return(FALSE);
  106.  
  107.  GfxBase = (struct GfxBase *) OpenLibrary("graphics.library", 39);
  108.  if(!GfxBase) return(FALSE);
  109.  
  110.  UtilityBase = (struct Library *) OpenLibrary("utility.library", 39);
  111.  if(!UtilityBase) return(FALSE);
  112.  
  113.  DataTypesBase = (struct Library *) OpenLibrary("datatypes.library", 39);
  114.  if(!DataTypesBase) return(FALSE);
  115.  
  116.  SuperClassBase = (struct Library *) OpenLibrary("datatypes/picture.datatype", 39);
  117.  if(!SuperClassBase) return(FALSE);
  118.  
  119.  IFFParseBase = (struct Library *) OpenLibrary("iffparse.library", 37);
  120.  if(!IFFParseBase) return(FALSE);
  121.  
  122.  
  123.  ClassBase->cb_SysBase        = (struct ExecBase      *) SysBase;
  124.  
  125.  ClassBase->cb_DOSBase        = (struct DosLibrary    *) DOSBase;
  126.  ClassBase->cb_IntuitionBase  = (struct IntuitionBase *) IntuitionBase;
  127.  ClassBase->cb_GfxBase        = (struct GfxBase       *) GfxBase;
  128.  ClassBase->cb_UtilityBase    = (struct Library       *) UtilityBase;
  129.  ClassBase->cb_DataTypesBase  = (struct Library       *) DataTypesBase;
  130.  ClassBase->cb_SuperClassBase = (struct Library       *) SuperClassBase;
  131.  ClassBase->cb_IFFParseBase   = (struct Library       *) IFFParseBase;
  132.  
  133.  if(ClassBase->cb_Class = initClass(ClassBase)) return(TRUE);
  134.  
  135.  return(FALSE);
  136. }
  137.  
  138. void __saveds __stdargs L_CloseLibs(void)
  139. {
  140.  if(ClassBase->cb_Class) FreeClass(ClassBase->cb_Class);
  141.  
  142.  if(IFFParseBase)   CloseLibrary((struct Library *) IFFParseBase);
  143.  if(SuperClassBase) CloseLibrary((struct Library *) SuperClassBase);
  144.  if(DataTypesBase)  CloseLibrary((struct Library *) DataTypesBase);
  145.  if(UtilityBase)    CloseLibrary((struct Library *) UtilityBase);
  146.  if(GfxBase)        CloseLibrary((struct Library *) GfxBase);
  147.  if(IntuitionBase)  CloseLibrary((struct Library *) IntuitionBase);
  148.  if(DOSBase)        CloseLibrary((struct Library *) DOSBase);
  149. }
  150.